#{extends 'main.html' /} #{set title:'Home' /}
<!-- @author Heidi eltoukhy

this page retrieves a list of all members joining a specific communityList -->

<p
	style="background-color: #FF6600; width: 400px; text-align: center; font-size: 20px;">
	<i> welcome to "
		${models.CommunityList.findById(Long.parseLong(session.get("CurrentCommList"))).name}
		" Community List </i>
</p>

<br>

#{if Long.parseLong(session.get("RegisteredUserId")) == x.creator.id}
<!-- Heidi ElToukhy
This is a button that enables the creator of a communityList to view a list of his received 
requests by other users to join the communityList
@author Heidi ElToukhy -->
<form action="@{CommunityLists.creatorRequests()}" method="get">
	<button name="RequestToJoin" type="submit">View Requests To
		Join CommunityList</button>
</form>
#{/if}
<!-- End @author Heidi ElToukhy-->
<!-- Start Mayar -->
<form action="@{CommunityLists.recommendedTopic()}" method="GET">
	<button name="commId" type="submit" value="${Open}"
		style="width: 306px;">Recommend A Topic To This Community
		List</button>
</form>

<form action="@{CommunityLists.recommendedExercise()}" method="GET">
	<button name="commId" type="submit" value="${Open}"
		style="width: 306px;">Recommend An Exercise To This Community
		List</button>
</form>

<form action="@{CommunityLists.recommendedTutorial()}" method="GET">
	<button name="commId" type="submit" value="${Open}"
		style="width: 308px;">Recommend A Tutorial To This Community
		List</button>
</form>

<!-- End Mayar -->

#{if Long.parseLong(session.get("RegisteredUserId")) == x.creator.id}
<form action="@{CommunityLists.AddMembersToExistingCommList()}"
	method="GET">
	<button name="Add Members">AddMembers</button>
</form>

#{/if}

<!-- Begin @author Ebaa
Two buttons one for assigning an owner to the community list that directs to another page called 
assignOwner and another for leaving the community list-->
#{if Long.parseLong(session.get("RegisteredUserId")) ==
models.CommunityList.findById(Open).getCreator().id}
<form action="@{CommunityLists.assignOwner()}" method="get">
	<button name="commListId" type="submit" value="${Open}">Assign
		Owner</button>
</form>
#{/if}
<script type="text/javascript">
	function confirmation() {
		var answer = confirm("Are you sure you want to leave this community list?")
		if (answer) {
			alert("You have left this community list sucsessfully")
			return true
		} else {
			return false
		}
	}
	function confirmation2() {
		var answer = confirm("You are the creator of the community list so you have to choose another one first, do you want to let the system assign?")
		if (answer) {
			return true
		} else {
			return false
		}
	}
	function confirmation3() {
		var answer = confirm("You are the creator of the community list but you have assigned an owner before so if you left now the owner willl be assigned as the creator, Are you sure you want to leave?")
		if (answer) {
			return true
		} else {
			return false
		}
	}
	function confirmation4() {
		var answer = confirm("You are the creator of the community list so you have to choose another one first, do you want to let the system assign?")
		if (answer) {
			alert ("There is no members in the community list to assign a creator from")
			return true
		} else {
			return false
		}
	}
</script>
#{if models.CommunityList.findById(Open).getMembersList().contains(models.RegisteredUser.findById(Long.parseLong(session.get("RegisteredUserId"))))}
#{if !(Long.parseLong(session.get("RegisteredUserId")) ==
models.CommunityList.findById(Open).getCreator().id)}
<form action="@{CommunityLists.leaveCommunityList()}" method="get">
	<button name="commListId" type="submit" value="${Open}"
		onClick="return confirmation()">Leave This Community List</button>
</form>
#{/if} #{/if} #{if Long.parseLong(session.get("RegisteredUserId")) == models.CommunityList.findById(Open).getCreator().id} #{if models.CommunityList.findById(Open).getOwner() == null} #{if models.CommunityList.findById(Open).getMembersList().size() != 0}
<form action="@{CommunityLists.leaveCommunityList()}" method="get">
	<button name="commListId" type="submit" value="${Open}"
		onClick="return confirmation2()">Leave This Community List</button>
</form>
#{/if} #{else}
<form action="@{CommunityLists.leaveCommunityList()}" method="get">
	<button name="commListId" type="submit" value="${Open}"
		onClick="return confirmation4()">Leave This Community List</button>
</form>
#{/else} #{/if} #{/if} #{if Long.parseLong(session.get("RegisteredUserId")) == models.CommunityList.findById(Open).getCreator().id} #{if models.CommunityList.findById(Open).getOwner() !=null}
<form action="@{CommunityLists.leaveCommunityList()}" method="get">
	<button name="commListId" type="submit" value="${Open}"
		onClick="return confirmation3()">Leave This Community List</button>
</form>
#{/if} #{/if}
<!-- End @author Ebaa-->
<!-- Begin @author Ayatullah Marawan
	button to view the community list score-->

<form action="@{CommunityLists.viewCommListScore()}" method="GET">
	<button name="Add Members">View CommList Score</button>
</form>
<!-- End @author Ayatullah Marawan-->


#{ifnot membersList}
<p
	style="background-color: #778899; width: 300px; text-align: top; font-size: 20px;">
	You have No CommunityList Members !!</p>
#{/ifnot} #{if !membersList.empty}
<form>
	<table width="300" id="dataTable" background="lightblue" ; border="2"
		; BORDERCOLOR=#FF6600>
		<tr>
			<th
				style="background-color: #778899; font-family: Arial; font-size: 20px"><p
					style="color: white;">Members</p></th>
			<th
				style="background-color: #778899; font-family: Arial; font-size: 20px"><p
					style="color: white;">Action</p></th> #{list items:membersList,as:'mList'}
		</tr>
		<td>
			<ul>
				<li><h4>
						${models.RegisteredUser.findById(mList.id).name} <br>
						<!-- Begin @author Ebaa
			            If the member is the owner of the community list, owner will be written besides his name-->
						#{if mList.ownerCommunityLists.contains(models.CommunityList.findById(Open))}
						Owner of this community List #{/if}
						<!-- End @author Ebaa-->
					</h4>
				</li>
			</ul>
		</td>
		<td>
			</div>
			<hr>
			</form> <!-- Begin @author Ebaa
			 A button that directs to other page called makeContributor--> #{if Long.parseLong(session.get("RegisteredUserId")) != models.CommunityList.findById(Open).getCreator().id } #{if models.CommunityList.findById(Open).getMembersList().contains(models.RegisteredUser.findById(Long.parseLong(session.get("RegisteredUserId"))))}
			#{if mList.id != Long.parseLong(session.get("RegisteredUserId"))}
			<form action="@{CommunityLists.makeContributor()}" method="get">
				<button name="userId" type="submit" value="${mList.id}">Make
					contributor</button>
			</form> #{/if} #{/if} #{/if} #{else}
			<form action="@{CommunityLists.makeContributor()}" method="get">
				<button name="userId" type="submit" value="${mList.id}">Make
					contributor</button>
			</form> #{/else} <!-- End @author Ebaa--></td> #{/list}
	</table>
	#{/if} <br> <br>
	<form>
		<li><a href="@{Application.viewProfile()}">Back to Profile
				Page</a></li>
	</form>
	<br>

	</body>